"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Logger_1 = require("../utils/Logger");
const Apple_1 = require("../../Apple");
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
const ws = require("ws");
let wsServerWorker; //wsServerWorker线程用来专门处理客户端请求连接
let arr = [];
if (isMainThread) {
    arr = [1];
    Logger_1.Logger.log("[mainThread] arr", arr);
    Logger_1.Logger.log("[mainThread]", __filename);
    wsServerWorker = new Worker(__filename, {
        workerData: []
    });
    wsServerWorker.on("message", (param) => {
        Logger_1.Logger.log("[mainThread] connection", param);
        Logger_1.Logger.log("[mainThread] connection", param.id, param.name);
        wsServerWorker.postMessage(param);
    });
    wsServerWorker.stdout.on('data', (data) => {
        Logger_1.Logger.log("[wsServerWorker]", data + "");
    });
    wsServerWorker.stderr.on('data', (data) => {
        Logger_1.Logger.error("[wsServerWorker]", data + "");
    });
}
else { //wsServerWorker线程
    console.log("wsServerWorker线程");
    const wsServer = new ws.Server({ port: 9696 });
    let connectNum = 0;
    wsServer.on('connection', function (connection) {
        // let socketConn = new SocketConnection(wsConnect);
        // SocketConnectionManager.instance.addSocketConnection(socketConn);
        connectNum++;
        console.log("connectNum====", connectNum, connection);
        let apple = new Apple_1.Apple(1, "testapple");
        parentPort.postMessage(connection);
        // parentPort.postMessage(apple);
    });
    parentPort.on('message', msg => {
        console.log("worker: receive ", msg);
    });
}
class wsServer {
}
exports.wsServer = wsServer;
